import { PrismaClient } from '@prisma/client';
import * as bcrypt from 'bcrypt';

const prisma = new PrismaClient();

async function verifyAdmin() {
  try {
    // 查找管理员
    const admin = await prisma.user.findFirst({
      where: {
        username: 'admin',
        role: 'ADMIN'
      }
    });

    if (!admin) {
      console.log('❌ 未找到管理员账号');
      return;
    }

    console.log('✅ 找到管理员账号:');
    console.log('  ID:', admin.id);
    console.log('  用户名:', admin.username);
    console.log('  昵称:', admin.nickname);
    console.log('  openid:', admin.openid);
    console.log('  角色:', admin.role);
    console.log('  密码哈希:', admin.password?.substring(0, 20) + '...');

    // 验证密码
    if (admin.password) {
      const isValid = await bcrypt.compare('admin123', admin.password);
      console.log('\n密码 "admin123" 验证结果:', isValid ? '✅ 正确' : '❌ 错误');
    } else {
      console.log('\n❌ 密码为空');
    }

  } catch (error) {
    console.error('验证失败:', error);
  } finally {
    await prisma.$disconnect();
  }
}

verifyAdmin();
